//
// Created by Administrator on 2016/10/24.
//

#include "Sky.h"

using namespace glm;

void ZainGL::Sky::draw(std::vector<glm::mat4> *const instanceTransforms) {
    glDepthFunc(GL_LEQUAL);  // Change depth function so depth test passes when values are equal to depth buffer's content

    mMaterial->active();

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_CUBE_MAP, mCubeMapTextureLoc);

    GLint skyBox = glGetUniformLocation(mMaterial->mShaderLoc, "skyBox");
    glUniform1i(skyBox, 0);

    // Draw mesh
    glBindVertexArray(mVAO);
    glDrawArrays(GL_TRIANGLES, 0, 36);
    glBindVertexArray(0);

    glDepthFunc(GL_LESS); // Set depth function back to default
}

ZainGL::Sky::Sky(const char *right, const char *left, const char *top, const char *bottom, const char *back,
                 const char *front, std::unordered_map<std::string, ZainTL::FileDatas> *bufferMap) {
    glGenVertexArrays(1, &mVAO);
    GLuint VBO = 0;
    glGenBuffers(1, &VBO);
    glBindVertexArray(mVAO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), skyboxVertices, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *) 0);
    glBindVertexArray(0);

    mCubeMapTextureLoc = loadCubeMap(right, left, top, bottom, back, front, bufferMap)->textureID;
}

void ZainGL::Sky::renderToShadowMap(std::vector<mat4> *const instanceTransforms) {
}
